#ifndef __PRODUCT_H__
#define __PRODUCT_H__
#include "allThread.h"
#include "function_interface.h"
#include "global_variable.h"
#include "rated_limit.h"
#include "fpga_interface.h"
#include "iso_interface.h"
#include "comm_monitor.h"

/************************************/

#if 1

#define DEVICE_STATE_HALT    (0)
#define DEVICE_STATE_WORK    (1)
#define DEVICE_STATE_FAULT   (2)

/* 控制模式 */
/* 控制模式 */
enum CONTROL_MODE
{
    UNKNOWN_CTRL_MODE 	= 0, //未知控制模式
    REMOTE_MODE 		= 1, //远程模式
    BMS_MODE			= 2, //BMS控制(no use)
    LOCAL_MODE 			= 3, //HMI本地模式
    DEBUG_MODE 			= 4, //上位机调试模式(no use)

    CTRL_MODE_MAX
};

/* 开关机记录 */
enum ON_OFF_RECORD
{
    UNKNOWN_ON_OFF		= 0, 
    ARM_OFF				= 1, 
    ARM_ON				= 2, 
    UPPER_OFF			= 3, 
    UPPER_ON			= 4, 
    LOCAL_OFF			= 5, 
    LOCAL_ON			= 6, 
    REMOTE_OFF			= 7, 
    REMOTE_ON			= 8,

    ON_OFF_RECORD_MAX
};

enum productOnOffCommander
{
    CMDER_LOWER,
    
    CMDER_SELF_OFF,                 /* ARM */
    CMDER_SELF_ON,      
    CMDER_UPPER_OFF,                /* 上位机 */
    CMDER_UPPER_ON,
    CMDER_HMI_OFF,                  /* 触摸屏 */
    CMDER_HMI_ON,
    CMDER_EXTERNAL_OFF,             /* 对外 */
    CMDER_EXTERNAL_ON,

    CMDER_TEMP_PROTECT_OFF,         /* 温度保护 */
    CMDER_TEMP_PROTECT_ON,
    CMDER_BAT_PROTECT_OFF,          /* 电池保护 */
    CMDER_BAT_PROTECT_ON,
    CMDER_FREQ_PROTECT_OFF,         /* 频率保护 */
    CMDER_FREQ_PROTECT_ON,
    CMDER_FAULT_RECOVERY_OFF,       /* 故障自恢复 */
    CMDER_FAULT_RECOVERY_ON,
    CMDER_COMM_PROTECT_EXTERNAL_OFF,/* 对外通信保护 */
    CMDER_COMM_PROTECT_EXTERNAL_ON,
    CMDER_COMM_PROTECT_BMS_OFF,     /* BMS通信保护 */
    CMDER_COMM_PROTECT_BMS_ON,
    CMDER_COMM_PROTECT_ISO_OFF,     /* 绝缘板通信保护 */
    CMDER_COMM_PROTECT_ISO_ON,
    CMDER_COMM_PROTECT_METER_OFF,   /* 电表通信保护 */
    CMDER_COMM_PROTECT_METER_ON,
    CMDER_LK_CUR_PROTECT_OFF,       /* 漏电流保护 */
    CMDER_LK_CUR_PROTECT_ON,
    CMDER_ISO_RES_PROTECT_OFF,      /* 绝缘电阻保护 */
    CMDER_ISO_RES_PROTECT_ON,
    CMDER_OL_PROTECT_OFF,           /* 过载 */
    CMDER_OL_PROTECT_ON,
    CMDER_L3_VOL_PROTECT_OFF,          /* 三级电压保护 */
    CMDER_L3_VOL_PROTECT_ON,
    CMDER_CUR_ZERO_PROTECT_OFF,     /* 电流回零保护 */
    CMDER_CUR_ZERO_PROTECT_ON,
    CMDER_L3_FREQ_PROTECT_OFF,          /* 三级频率保护 */
    CMDER_L3_FREQ_PROTECT_ON,
    CMDER_OIL_TEMP_PROTECT_OFF,          /* 油温保护 */
    CMDER_OIL_TEMP_PROTECT_ON,
    CMDER_OIL_PRES_PROTECT_OFF,          /* 油压保护 */
    CMDER_OIL_PRES_PROTECT_ON,
    CMDER_OIL_POS_PROTECT_OFF,          /* 油位保护 */
    CMDER_OIL_POS_PROTECT_ON,
    CMDER_LOAD_BRK_PROTECT_OFF,          /* 负荷分闸保护 */
    CMDER_LOAD_BRK_PROTECT_ON,
    CMDER_FAN_PROTECT_OFF,          /* 风机保护 */
    CMDER_FAN_PROTECT_ON,
};

#endif

void Product_OnOffThread(void* pPara);
void Product_Thread(void* pPara);
void Product_EmsInputEmergencyStop(void);
void Product_TransformerStateHandle(void);
void Product_CurZeroUpdate(void);
void Product_OverLeakCur(void);
void Product_PeakLoadShifting(void);

#endif
